package leetcode.code1985;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

public class Kth {

	class MyComp implements Comparator<Integer> {

		@Override
		public int compare(Integer o1, Integer o2) {
			return o1 - o2;
		}

	}

	public static void main(String[] args) {
		List<Integer> list = new ArrayList<>();
		list.addAll(Arrays.asList(new Integer[] { 1, 4, 3 }));

//		Stream.of(list).max((a, b) -> a.get(0) - b.get(0));
		int max = list.stream().max((a, b) -> b - a).get();
		Integer[] arr = new Integer[10];
		Arrays.sort(arr, (a, b) -> b - a);
		System.out.println("hello " + max);
//		Collections.sort(list, (a, b) -> b - a);
//		for (int i : list) {
//			System.out.println(i);
//		}
//		System.out.println(list.get(list.size() - 1));
//		Kth k = new Kth();
//		k.f1(list);
//		k.f2(list);
//		k.f3(list);
//		k.f4(list);
//		k.f5(list);
	}

	// log n
	private void f5(List<Integer> list) {
		// TODO Auto-generated method stub

	}

	// n
	private void f4(List<Integer> list) {
		int len = list.size();
		int ans = 0;
		for (int i = 0; i < len; i++) {
//			ans = Math.max(ans, list.get(i));
			if (list.get(i) > ans) {
				ans = list.get(i);
			}
		}
		System.out.println(ans);
	}

	private void f3(List<Integer> list) {
		int[] arr = new int[list.size()];
		for (int i = 0; i < list.size(); i++) {
			arr[i] = list.get(i);
		}
		int max = Arrays.stream(arr).max().getAsInt();
		System.out.println(max);
	}

	// n * log n
	private void f2(List<Integer> list) {
		Collections.sort(list);
		System.out.println(list.get(list.size() - 1));
	}

	// n * n
	public void f1(List<Integer> list) {
		int len = list.size();
		int ans = 0;
		for (int i = 0; i < len; i++) {
			for (int j = i + 1; j < len; j++) {
				if (list.get(i) > list.get(j)) {
					ans = Math.max(ans, list.get(i));
				}
			}
		}
		System.out.println(ans);
	}

}
